package com.slixils.demo.controller;

import com.slixils.demo.service.UserService;
import com.slixils.demo.vo.LoginVo;
import com.slixils.demo.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @Author: JinChongLi
 * @Description:
 * @Date: Created in 5:14 2022/4/5
 * @Modified By:
 */
@Slf4j
@Controller
@RequestMapping("/login")
public class loginController {
    @Autowired
    private UserService userService;
    /**
     * 跳转登录页
     *
     * @return
     */
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }
    /**
     * 登录
     * @return
     */
    @RequestMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(@Valid LoginVo loginVo, HttpServletRequest request, HttpServletResponse response) {
        log.info(loginVo.toString());
        System.out.println(loginVo);
        RespBean login = userService.login(loginVo, request, response);
        return login;
    }
}
